package Env;

import jpa.E1;
import jpa.E1Dao;
import gwt.common.SpringUtil;
import gwt.coonay.client.NoteDTO;
import gwt.coonay.server.JpaNoteDao;
import gwt.coonay.server.Note;

import org.springframework.context.ApplicationContext;

import com.google.appengine.api.datastore.dev.LocalDatastoreService;
import com.google.appengine.tools.development.ApiProxyLocalImpl;
import com.google.apphosting.api.ApiProxy;

public class LocalDatastoreTestCase extends LocalServiceTestCase {

    @Override
    public void setUp() throws Exception {
        super.setUp();
        ApiProxyLocalImpl proxy = (ApiProxyLocalImpl) ApiProxy.getDelegate();
        proxy.setProperty(LocalDatastoreService.NO_STORAGE_PROPERTY, Boolean.TRUE.toString());
        
        
        
    }
    
    
    public void testNoteJpa(){
    	SpringUtil.initIOCFactory();
    		
		JpaNoteDao jnd = (JpaNoteDao)SpringUtil.getBean("noteDao");
		jnd.loadAll();
		
		
		NoteDTO note = new NoteDTO();
		note.setGmail("t@163.com");	
		Note n = Note.newInstance(note);
		n.mail2 = "mail2@163.com";
		jnd.create(n);
		jnd.loadAll();
    }
    
    
    
    public void testE1Jpa(){
    	SpringUtil.initIOCFactory();
    		
    	E1Dao ed = (E1Dao)SpringUtil.getBean("e1Dao");
		ed.loadAll();
		
		
		E1 e1 = new E1();
		e1.setGmail("t@163.com");	
		ed.create(e1);
		ed.loadAll();
    }

    @Override
    public void tearDown() throws Exception {
        ApiProxyLocalImpl proxy = (ApiProxyLocalImpl) ApiProxy.getDelegate();
        LocalDatastoreService datastoreService = (LocalDatastoreService) proxy.getService("datastore_v3");
        datastoreService.clearProfiles();
        super.tearDown();
    }

}